package com.example.demo.mq.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;

/**
 * 接口用于实现消息发送到RabbitMQ交换器后接收ack回调   即消息发送到exchange
 * confirm机制是只保证消息到达exchange，并不保证消息可以路由到正确的queue
 */
@Slf4j
public class MessageConfirmCallback implements RabbitTemplate.ConfirmCallback {

    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        if (ack) {
            log.info("消息发送到exchange成功");
        } else {
            log.error("消息发送到exchange失败,原因: {}", cause);
        }
    }

}
